<template>
  <el-dialog
    title="上传因果图"
    :visible.sync="uploadDialogVisible"
    width="30%">
    <el-upload
  class="upload-demo"
  drag
  action="http://192.168.43.7:1013/upload"
  :data="data"
  :on-success="handleUploadSuccess"
  :headers="{'Authorization': 'Bearer ' + token}  "
  multiple>
  <i class="el-icon-upload"></i>
  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
  <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
</el-upload>
    <span slot="footer" class="dialog-footer">
      <el-button @click="uploadDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="uploadDialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
  export default {
    props:{
      logId:{
        type:Number,
        required:true
      }
    },
    data() {
      return {
        uploadDialogVisible: false,
        token:localStorage.getItem('token'),
        data:{
          "log_id":this.logId
        }
      };
    },
    methods:{
      handleUploadSuccess() {
            // 这里是文件上传成功后的逻辑，比如关闭上传对话框等
            this.uploadDialogVisible=false;
            // 然后触发自定义事件
            this.$emit('upload-success');
        }
    },
    // 父组件传来的值是动态变化的
    watch: {
    logId(newValue) {
      this.data.log_id = newValue;
    }
   }   
  };
</script>